package com.hifar.plat.maindatasource.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
import com.hifar.plat.maindatasource.service.ICollectdbDataSourceService;

@Service
@DS("collectdb")
public class CollectdbDataSourceImpl implements ICollectdbDataSourceService {

	@Value("${spring.datasource.dynamic.datasource.collectdb.dbtype:error}")
	private String dbtype;
	@Override
	public String getDbType() {
		 return dbtype;
	}
	@Override
	@Transactional
	public int selectCount(String sql, Object... args) {
		return SqlRunner.db().selectCount(sql, args);
	}

	@Override
	@Transactional
	public boolean insert(String sql, Object... args) {
		return SqlRunner.db().insert(sql, args);
	}

	@Transactional
	@Override
	public boolean delete(String sql, Object... args) {
		return SqlRunner.db().delete(sql, args);
	}
	
	@Transactional
	@Override
	public boolean update(String sql, Object... args) {
		return SqlRunner.db().update(sql, args);
	}

	@Override
	@Transactional
	public <E extends IPage<Map<String, Object>>> E selectPage(E page, String sql, Object... args) {

		return SqlRunner.db().selectPage(page, sql, args);
	}

	@Override
	@Transactional
	public List<Map<String, Object>> selectList(String sql, Object... args) {
		return SqlRunner.db().selectList(sql, args);
	}

	@Override
	@Transactional
	public List<Map<String, Object>> nativeSql(String nativeSql) {
		return SqlRunner.db().selectList(nativeSql);
	}
	@Override
	public Map<String, Object> selectOne(String sql, Object... args) {
		Map<String,Object> oneMap=null;
		try {
			oneMap=SqlRunner.db().selectOne(sql, args);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 	 oneMap;
	}
}
